
/*__________________________________________点击编辑___________________________________________________*/
	$(".mainTable table").delegate(".edit","click",function(){
		var postId = $(this).parent().find("span[class=postId]").text()
		var signId = $(this).parent().find("td[class=signId]").text()
		layer.open({
			type: 2,
			title: ['航班信息修改','background-color:#00aa98; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			area: ['840px', '500px'],  
			content: ["../ak/flightMessageEdit.html?postId="+postId+"&signId="+signId+"&temp="+Math.random()]  // iframe的url，no代表不显示滚动条				
		});
		
	})
		
/*__________________________________________点击全选_____________________________________________*/	
	$(".checkAll").click(function(){
		if(this.checked){
			$(".check").prop('checked','checked')				
		}else{
			$(".check").prop('checked',false)		
		}
	})
	
/*_________________________________________点击取消航班_____________________________________________*/	
	$(".cancleFlight").click(function(){
		var length = $('.clear tr td input:checkbox').length
		var arrIndex = [];
		var postArr = [];
		for(var i=0;i<length;i++){
			if($('table tr td input:checkbox')[i].checked){	
				var that = $('table tr td input:checkbox')[i].checked
				arrIndex.push(i)				
			}
		}
		
		for(var i=0;i<arrIndex.length;i++){
			var sign = $(".clear tr input:checkbox").eq(arrIndex[i]).parent().find("span[class=postId]").text()			
			postArr.push(sign)
		}
		if(arrIndex.length==0){
			layer.msg("请选择需要取消的航班！",{icon:2})
			return false;
		}else{
			//询问框
			layer.confirm('确认取消该航班？', {
					title:['温馨提示','background-color:#00aa98;color:#fff'],
				   	btn: ['确定','取消'] //按钮
				}, function(){
					layer.msg('取消中...', {icon: 16,shade: 0.01});
					$.ajax({
						type:"post",
						url:"../flight/cancel?&temp="+Math.random(),
						contentType:'application/json;charset=utf-8',
						async:true,
						data:JSON.stringify(postArr),
						success:function(data){
							data = JSON.parse(data)
							console.log(data)
							if(data.status=='1001'){
								layer.msg('已取消', {icon: 1},function(){
									getAjax()
								});
							}if(data.status=='1002'){
								/*layer.msg('取消失败！'+data.message, {icon: 2,time:2000},function(){
									getAjax()
								});*/
								//失败的弹出框
								layer.confirm(data.message, {
									title:['取消失败','background-color:#00aa98;color:#fff'],
								   	btn: ['确定'] //按钮
								}, function(){
									layer.closeAll('dialog');
									getAjax();
								});
							}
							
							
						}			
					});	
				});	
		}				
	})
	
/*_________________________________________点击查询按钮_____________________________________________*/	
	
	$(".querySpan").click(function(){
		$(".page").val("1")
		getAjax()
	})
/*_________________________________________点击排序_____________________________________________*/	
	$(".sort").click(function(){
		
	})
/*_________________________________________点击详情___________________________________*/	
	$("table").delegate(".detail","click",function(){
		var signId = $(this).parent().find("td[class=signId]").text()		
		if($(this).html()=='详情'){
			var that = this;
			layer.load();
			$.get("../flight/leg/"+signId+"?&temp="+Math.random(),function(data){
				layer.closeAll('loading');
				data = JSON.parse(data)
				var totalSeat = 0;
				var str= "<div class='clickDetail f262929'>" +
						 "<p>航班机型 : <span class='f00aa99'>"+data.data.aircrftName+"</span></p>"
				for(var i in data.data.invLegCabinVos){
					totalSeat += data.data.invLegCabinVos[i].capacity
					str+="<p>"+data.data.invLegCabinVos[i].cabinName+" : <span class='f00aa99'>"+data.data.invLegCabinVos[i].capacity+"</span></p>"
				}		
					str+="<p>座位总数 : <span class='f00aa99'>"+totalSeat+"</span></p>"+
						 "</div>"	
							
					$(that).append(str)
			})			
		}else{
			$(this).html('详情')
		}
		
	})
	
/*_________________________________________点击航班号进入设置航段___________________________________*/	
	$("table").delegate(".airlineCode","click",function(){
		var airlineCodeId = $(this).next().text();//获取航班id
		layer.open({
			type: 2,
			title: ['设置航段信息','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['940px', '90%'],  
			content: ['../ak/setLegInventory.html?airlineCodeId='+airlineCodeId],  // iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}	
		});
		
	})
//点击航班号进入航段设置2——————————————————————————————————————————————————————————————————————————————
	/*$("thead").click(function(){
		var airlineCodeId = $(this).next().text();//获取航班id
		layer.open({
			type: 2,
			title: ['设置航段','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['940px', '90%'],  
			content: ['../ak/setFlightLeg.html?airlineCodeId='+airlineCodeId],  // iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}	
		});
	})*/
/*_______________________________________封装ajax请求函数_____________________________________________*/		
	var totalAmount
	var totalPage
	var nowPage
	function getAjax(){
		var airlineCode = ($(".flightNo").val()).toUpperCase();
		var startDate = $(".startTime").val();
		var endDate = $(".endTime").val();
		var pageNum = $(".page").val();
		var pageSize = $(".pageSize").val();
		var status = $(".searchStatus").val();
		var dayOfWeek = $(".dayOfWeek").val();
		if(/\((.)+?\)/.test($(".dep").val())){//获取出发机场三字码
			var dep = $(".dep").val().slice(-5).split("(")[1].split(")")[0];
		}else{
			var dep = $(".dep").val()
		}
		if(/\((.)+?\)/.test($(".arr").val())){//获取到达机场三字码
			var arr = $(".arr").val().slice(-5).split("(")[1].split(")")[0];
		}else{
			var arr = $(".arr").val()
		}
		layer.load();
		$.ajax({
			type:"get",
			url:"../flight?airlineCode="+airlineCode+"&dep="+dep+"&arr="+arr+"&dayOfWeek="+dayOfWeek+"&status="+status+"&startDate="+startDate+"&endDate="+endDate+"&pageNum="+pageNum+"&pageSize="+pageSize+"&temp="+Math.random(),
			dataType:"json",
			success:function(data){
				layer.closeAll("loading");
				//每次经行请求时清空页面原有数据
				$(".clear").empty();
				totalAmount = data.data.total
				totalPage = data.data.pages
				nowPage = data.data.pageNum
				if(totalAmount=="0"){
					layer.msg("没有搜索到结果")
					return false;
				}
				//共多少条
				$(".totalAmount").text(totalAmount)				
				//共多少页
				$(".totalPage").text(totalPage)
				//第几页
				$(".nowPage").text(nowPage)
								
				var str="";		
				for(var i=0;i<data.data.list.length;i++){			
					var length = data.data.list[i].flightLegVos.length
					for(var j=0;j<data.data.list[i].flightLegVos.length;j++){
						var str1 = "";
						var str2 = "";
						if(data.data.list[i].flightLegVos[j].depDc=="0"){
							str1+="";
						}else{
							str1+="+<span class='f00aa99'>"+data.data.list[i].flightLegVos[j].depDc;
						}
						if(data.data.list[i].flightLegVos[j].arrDc=="0"){
							str2+="";
						}else{
							str2+="+<span class='f00aa99'>"+data.data.list[i].flightLegVos[j].arrDc;
						}
						if(data.data.list[i].status=="1"){	
							data.data.list[i].status="执行中";
							
						}											
						else{				
							if(data.data.list[i].status=="2"){
								data.data.list[i].status="已取消"	
									
							}else{
								data.data.list[i].status="未知状态"	
									
							}
						}
						
						
						if(j==0){
							str+="<tr>" +
							   		"<td rowspan = "+length+" class='flightNumId'><input class=check type='checkbox'/><span class='airlineCode faa000'>"+data.data.list[i].airlineCode+"</span><span style='display:none' class='postId'>"+data.data.list[i].id+"</span></td>"
						}else{
							str+=""
						}
							str+= "<td><span class='font14px f262929'>"+data.data.list[i].flightLegVos[j].depAirportName+"&nbsp;(&nbsp;"+data.data.list[i].flightLegVos[j].depAirport+"&nbsp;)&nbsp;<span class='f00aa99'>"+data.data.list[i].flightLegVos[j].depTerminal+"</span></span></br><span class='thisLegDepDate f00aa99'>"+data.data.list[i].flightLegVos[j].thisLegDepDate+"</span>&nbsp;&nbsp;&nbsp;"+data.data.list[i].flightLegVos[j].depTime+str1+"</span></td>" +
								  "<td><span class='font14px f262929'>"+data.data.list[i].flightLegVos[j].arrAirportName+"&nbsp;(&nbsp;"+data.data.list[i].flightLegVos[j].arrAirport+"&nbsp;)&nbsp;<span class='f00aa99'>"+data.data.list[i].flightLegVos[j].arrTerminal+"</span></span></br><span class='thisLegDepDate f00aa99'>"+data.data.list[i].flightLegVos[j].thisLegArrDate+"</span>&nbsp;&nbsp;&nbsp;"+data.data.list[i].flightLegVos[j].arrTime+str2+"</span></td>" +			
								  "<td>"+commomFun.skTypeToStr(data.data.list[i].skStatus)+"</td>"+
								  "<td class='detail faa000'>详情</td>"+
								  "<td style='display:none;' class='signId'>"+data.data.list[i].flightLegVos[j].id+"</td>"
						if(j==0){										
							str+= 
								  "<td class='font14px f262929' rowspan = "+length+">"+data.data.list[i].createUserName+"</td>" +
								  "<td rowspan = "+length+" class='status'>"+data.data.list[i].status+"</td>" 							 				  
							      
						}
							str+="</tr>"
					}
				}
				$(".clear").append(str)
				/*控制不同的状态，字体颜色不同begin*/
				for(var i=0;i<$(".clear>tr").length;i++){
					if($(".status").eq(i).text()=="执行中"){
						$(".status").eq(i).addClass("fa2828");
					}else{
						$(".status").eq(i).addClass("aaaaaa");
					}
				}
				/*控制不同的状态，字体颜色不同end*/
			}									
		});	
	}
	
	/*——————————————————————————————————————批量管理————————————————————————————————————————————————————————————*/

	$('.lot_manage').click(function(){
		//var id=$(this).prev().prev().val();//获取当前行的id值
		var checkArr = [];
		var listIds=[];//存放每条id的数组
		var length = $('.clear tr td input:checkbox').length;
		
		for(var i=0;i<length;i++){
			if($('.clear tr td input:checkbox')[i].checked){
				checkArr.push(i);
			}
		}		
		for(var i=0;i<checkArr.length;i++){
			var list_id= $(".postId").eq(checkArr[i]).text();
			listIds.push(list_id);
		}
		if(listIds.length==0){
			layer.msg("请选择所要修改的航班",{icon:2})
			return false;
		}else{
			layer.open({
			type: 2,
			title: ['批量修改','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['500px', '400px'],  
			content: ['../ak/batchInventoryModify.html?listIds='+listIds],  // iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
				if($(".checkAll").is(":checked")){
					$(".checkAll").prop('checked',false);
				}
			}	
		   });
		}				
	})	  
//________________________________________表头固定____________________________________________
		$("#dataTable").freezeHeader();	
//___________________________________________分页______________________________________________
	 	$(".Pagination").load("Pagination.html",function(){
	 		getAjax()
	 	})
//___________________________________________机场联想_________________________________________
	 	airportAutoComplete()	
		function airportAutoComplete(){
			var autocompleteData=[];
			$.ajax({
				type:"get",
				url:"../Airapt?pageSize=100000&pageNum=1&temp="+Math.random(),
				dataType:"json",
				success:function(data){	
					autocompleteData = data.data.list; 
					$('.autocomplete').autocomplete({
					    lookup: autocompleteData,
					    autoSelectFirst:true,
					    onSelect: function (suggestion) {		   
					    }
					});
				}
			})
		}
//________________________________________________________________城市交换
	 	$(".exchangeAirportCode").click(function(){
			var exchangeVar = $(".dep").val();
			$(".dep").val($(".arr").val());
			$(".arr").val(exchangeVar);
		})
	
	